package cn.edu.flink.tutorial.transform;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Filter {
    public static void main(String[] args) throws Exception {
        // 创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 从文件中读取数据
        String inputPath = "hello.txt";
        DataStreamSource<String> streamSource = env.readTextFile(inputPath);

        DataStream<String> output = streamSource.filter(
                new FilterFunction<String>() {
                    @Override
                    public boolean filter(String s) throws Exception {
                        if (s.contains(" ")) {
                            return true;
                        }
                        return false;
                    }
                }
        );

        output.print();

        env.execute();
    }
}
